﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Backend.Data.Entities;

namespace Backend.Data.Mappings
{
    class OrganigramaMap : EntityTypeConfiguration<Organigrama>
    {
        public OrganigramaMap()
        {
            //table
            ToTable("Organigramas");

            //pk
            HasKey(t => t.Id);

            //property
            Property(t => t.Id)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            Property(t => t.Alias)
                .IsOptional();
            Property(t => t.Name)
                .IsRequired();

            // 0.1 to 0.* permite null: puede o no tener un Parent
            HasOptional(x => x.Parent)
               .WithMany(x => x.Organigramas)
               .HasForeignKey(x => x.ParentId)
               .WillCascadeOnDelete(false);


        }
    }
}
